import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class NeighboringNumbers {

	public static void main(String[] args) throws NumberFormatException,
			IOException {

		Map<String, String> pairInfo = getPairInfo(Input.parse("Enter several numbers in a row: "));
		System.out.println("Pair of neighboring numbers with minimum distance: ");
		for (Map.Entry entry : pairInfo.entrySet()) {
			System.out.printf("[%s]: %s", entry.getKey(), entry.getValue()).println();
		}
	}

	public static Map getPairInfo(String[] userInput) {
		int[] integers = convertToIntArray(userInput);
		int index = findMinIndex(integers);

		Map<Object, Object> result = new HashMap<Object, Object>();
		result.put(index, integers[index]);
		result.put(index + 1, integers[index + 1]);
		result.put("min distance", Math.abs(integers[index + 1] - integers[index]));
		result.put("1-st element index", index);

		return result;
	}

	public static int findMinIndex(int[] integers) {
		int result = 0;
		for (int i = 1; i < integers.length - 1; i++) {
			if (Math.abs(integers[i + 1] - integers[i]) < Math
					.abs(integers[result + 1] - integers[result])) {
				result = i;

			}
		}
		return result;
	}

	public static int[] convertToIntArray(String[] string) {
		int[] result = new int[string.length];
		for (int i = 0; i < string.length; i++) {
			result[i] = Integer.parseInt(string[i]);
		}
		return result;
	}

}
